package com.bilin.coin.activity;

import android.view.View;
import android.widget.Button;
import android.widget.ImageView;

import com.alibaba.android.arouter.facade.annotation.Route;
import com.bilin.coin.ApiConstant;
import com.bilin.coin.R;
import com.bilin.coin.bean.GoldRechargeRecordBean;
import com.bilin.coin.bean.MyMillBean;
import com.bilin.coin.tools.AbsHeadRecycleViewActivity;
import com.bilin.coin.tools.Poster;
import com.bilin.coin.utils.GlideUtils;
import com.bilin.coin.utils.GsonUtil;
import com.chad.library.adapter.base.BaseViewHolder;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Route(path = "/auction/MyMillListActivity")
public class MyMillListActivity extends AbsHeadRecycleViewActivity<MyMillBean.RecordsBean> {


    @Override
    protected void initView() {
        super.initView();
        setTitle("我的矿机");
    }

    @Override
    protected void convertItem(BaseViewHolder helper, MyMillBean.RecordsBean item) {

        ImageView iv1 = helper.getView(R.id.iv1);
        Button bt_confirm = helper.getView(R.id.bt_confirm);
        String imgUrl = item.getBlDevice().getImgUrl();
        if (imgUrl.startsWith("http")) {
            GlideUtils.getInstance().displayImageWidth(this,imgUrl, iv1);
        } else {
            GlideUtils.getInstance().displayImageWidth(this, ApiConstant.OSSURL + imgUrl, iv1);
        }
        helper.setText(R.id.tv_name, item.getBlDevice().getName());
        helper.setText(R.id.tv_gold, "金豆总奖励:"+item.getBlDevice().getAwardJd());
        helper.setText(R.id.tv_work_time, "工作时间:"+item.getBlDevice().getWorkTime());
        helper.setText(R.id.tv_valid_time, "有效期:"+item.getValidTime());
        bt_confirm.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                xuqi(item.getId());
            }
        });
    }

    private void xuqi(String id) {
        new Poster(this, true, true) {
            @Override
            protected String fillUrl() {
                return "/api/bl-my-device/again";
            }

            @Override
            protected Map<String, String> fillParams() {
                HashMap hashMap = new HashMap();
                hashMap.put("id",id+"");
                return hashMap;
            }

            @Override
            protected void disposeSuccess(String dataJson) {
                super.disposeSuccess(dataJson);
                refresh(true);
            }
        };
    }

    @Override
    protected int fillItemLayout() {
        return R.layout.item_my_mill;
    }

    @Override
    public int fillPageSize() {
        return 10;
    }

    @Override
    public boolean isPost() {
        return false;
    }

    @Override
    public String fillUrl() {
        return "/api/bl-my-device/myDevice";
    }

    @Override
    protected View fillHeadView() {
        return new View(this);
    }

    @Override
    public Map<String, String> fillParams() {
        HashMap params = new HashMap();
        params.put("currentPage", page + "");
        params.put("pageSize", pageSize + "");
        return params;
    }

    @Override
    public List parseListDataAndFillTotal(String dataJson) {
        GoldRechargeRecordBean goldRechargeRecordBean = GsonUtil.GsonToBean(dataJson, GoldRechargeRecordBean.class);
        totalCount = goldRechargeRecordBean.getTotal();
        return goldRechargeRecordBean.getRecords();
    }

    @Override
    protected void refreshFragmentOrHead() {

    }
}
